package com.joey.concurrency.example.count;

import com.joey.concurrency.annotation.NotThreadSafe;

/**
 * @Author hyy
 **/
@NotThreadSafe
public class AtomicBooleanNotSafeExample implements Runnable{

    private boolean someone = false;

    @Override
    public void run() {
        if (!someone) {
            try {
                Thread.sleep(1000);
                someone = true;
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName()+" i am coming");
            System.out.println(Thread.currentThread().getName()+" i have to leaving");
            someone = false;
        }else{
            System.out.println(Thread.currentThread().getName()+" i can't visit the house!");
        }
    }

    public static void main(String[] args) {
        AtomicBooleanNotSafeExample obj = new AtomicBooleanNotSafeExample();
        new Thread(obj,"Thread1").start();
        new Thread(obj,"Thread2").start();
    }
}
